package kr.saeildamil.androidforstudy2.ch23;

import kr.saeildamil.androidforstudy2.R;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.TextSwitcher;
import android.widget.TextView;
import android.widget.ViewSwitcher;

public class TextSwitcherTest extends Activity {
	TextSwitcher mSwitcher;
	int mAdvertisement;
	
	String[] arAdvertisement = new String[]{
		"어젯밤, 저택에서 원인 모를 급습 발생",
		"피해자는 소환수들",
		"프리트, 어제의 급습은 다모 씨 탓이라고 비난",
		"다모 씨, 자신은 억울하다며 호소",
		"정령들, 어둠을 머금은 망토자락 목격",
		"범인은 검은 고양이 정령인 플루토로 밝혀져 파문",
		"프리트와 정령들, 다모 씨에게 사과"
	};
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch23_textswitchertest);
		
		mSwitcher = (TextSwitcher) findViewById(R.id.ch23_textswitchertest_textswitcher);
		mSwitcher.setFactory(mFactory);
	
		mSwitcher.setText(arAdvertisement[mAdvertisement]);
	}
	
	public void mOnClick(View v){
		switch (v.getId()) {
		case R.id.ch23_textswitchertest_nextbtn:
			mAdvertisement = mAdvertisement == arAdvertisement.length -1 ? 0:mAdvertisement + 1;
			mSwitcher.setText(arAdvertisement[mAdvertisement]);
			break;
		}
	}
	
	ViewSwitcher.ViewFactory mFactory = new ViewSwitcher.ViewFactory() {
		
		@Override
		public View makeView() {
			TextView text = new TextView(TextSwitcherTest.this);
			text.setTextSize(20);
			text.setBackgroundColor(Color.LTGRAY);
			text.setTextColor(Color.BLACK);
			return text;
		}
	};
	
}
